package com.kgc.activityprovider.service.impl;

import com.kgc.activiti.util.ResponseMsg;
import com.kgc.activityprovider.dao.CGWorkFlowMapper;
import com.kgc.activityprovider.feign.cg.CgddOrderFeign;
import com.kgc.activityprovider.service.WorkFlowUtilService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Service("cGDDServiceImpl")
public class CGDDServiceImpl implements WorkFlowUtilService {
    private Logger logger = LoggerFactory.getLogger(CGDDServiceImpl.class);

    @Resource
    private CgddOrderFeign cgddOrderFeign;

    @Resource
    private CGWorkFlowMapper cgWorkFlowMapper;

    private final String TABLE = "cg_ecgdd";

    @Override
    public ResponseMsg changeStatus(String code, int status) {
        logger.info("changeStatus:code{},status{}", code,status);
        ResponseMsg responseMsg = new ResponseMsg();
        responseMsg.setCode("201");
        Map<String , Object> map = new HashMap<String , Object>();
        map.put("status", status);
        map.put("code", code);
        map.put("table", TABLE);
        int result = cgWorkFlowMapper.checkOrderStatus(map);
        if (result <= 0){
            responseMsg.setMsg("changeStatus 更新失败");
            return responseMsg;
        }
        if (status == 3){
            cgddOrderFeign.passCGDD(code);
            responseMsg.setData("changeStatus success");
        }
        responseMsg.setCode("200");
        logger.info("changeStatus:code{},status{} ,responseMsg{}" , code,status ,responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg insertCheck(String code, Integer checkManId, String checkComment) {
        logger.info("insertCheck code{},checkManId{},checkComment{}", code,checkManId,checkComment);
        ResponseMsg responseMsg = new ResponseMsg();
        responseMsg.setCode("201");
        Map<String,Object> map =new HashMap<>();
        map.put("checkManId", checkManId);
        map.put("checkComment", checkComment);
        map.put("code", code);
        map.put("table", TABLE);
        int result = cgWorkFlowMapper.insertCheckCwOtherIncome(map);
        if (result <= 0){
            return responseMsg;
        }
        responseMsg.setCode("200");
        responseMsg.setData("insertCheck success");
        logger.info("insertCheck code{},checkManId{},checkComment{},responseMsg{}", code,checkManId,checkComment,responseMsg);
        return responseMsg;
    }
}
